$(function () {
    //页面渲染
    $.ajax({
        url: bignews.user_detail,
        headers: { Authorization: localStorage.getItem('token') },
        success: function (res) {
            let html = template('textTemp', res.data)
            $('.common_con').html(html)
        }
    })
    //编辑个人主页
    $('.common_con').on('click', '.btn-edit', function () {
        let formdata = new FormData($('#form')[0])
        $.ajax({
            url: bignews.user_edit,
            type: 'post',
            data: formdata,
            headers: { Authorization: localStorage.getItem('token') },
            contentType: false,
            processData: false,
            success: function (res) {
                if (res.code == 200) {
                    alert('更新成功')
                    window.parent.location.reload()
                }

            },
            dataType: 'json'
        })
    })

    //图片预览
    /* $('.common_con').on('change', '#exampleInputFile', function () {
        let file = this.files[0]
        console.log(file)
        let url = URL.createObjectURL(file)
        $('.user_pic').attr('src', url)
    }) */


    $('.common_con').on('change', '#exampleInputFile', function () {
        //获取用户选择的文件
        let file = this.files[0]
        console.log(file)
        //将文件转化为src属性
        let url = URL.createObjectURL(file)
        //重新赋值给图片src属性
        $('.user_pic').prop('src', url)
    })
})